from django.views import View
from django.shortcuts import render, loader, HttpResponse
import json


# Create y
#
#
# our views here.
class BookView(View):

    # 前后端分离，返回json
    def get(self, request):
        get_params = json.dumps(request.GET)
        return HttpResponse("前后端分离: " + get_params)

    # 使用template的load方法
    def t_loader(self, request):
        t = loader.get_template('test.html')
        html = t.render({'name': 'render template-->loader'})  # 以字典形式传递数据并生成html
        return HttpResponse(html)  # 以 HttpResponse方式响应html

    # 使用template的load方法
    # def get(self, request):
    #     return render(request, 'test.html', {'name': 'render template-->render'})  # 根据字典数据生成动态模板


def year_test(request, year):
    return HttpResponse(f"year: {year}")


def month_test(request, year, month):
    return HttpResponse(f"year: {year}, month:{month}")


def article_test(request, year, month, slug):
    return HttpResponse(f"year: {year}, month:{month}, slug:{slug}")


def slug_test2(request, slug):
    return HttpResponse(f"slug2:{slug}")


def slug_test3(request, slug):
    return HttpResponse(f"slug3:{slug}")


def slug_test4(request, slug):
    return HttpResponse(f"slug4:{slug}")
